import random

import redis
import requests


def should_request(url):
    client = redis.Redis(host='localhost', port=6379, db=1,password='123456')
    task_list = client.lrange("task", 0, -1)
    return url.encode('utf-8') in task_list

def sava_data(url):
    client = redis.Redis(host='localhost', port=6379, db=1,password='123456')
    client.lpush("task", url)



def main():

    urls = [f"https://httpbin.org/get?age={random.randint(1, 30)}"  for i in range(10)]


    for url in urls:
        if not should_request(url):
            response = requests.get( url)
            sava_data(url)
            print("请求保存")
        else:
            print("有重复")




main()